package chp07;

import java.util.Scanner;

public class Test12c {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        //删除
        String[] names = {"jack","tom","mike","peter","jim"};
        System.out.println("序号\t姓名");
        for (int i = 0; i < names.length; i++) {
            System.out.println((i+1) +"\t\t"+names[i]);
        }
        System.out.println("请输入需要删除姓名的坐标:");
        int index = input.nextInt();
        //把用户输入的值(从1开始)转为数组的坐标(从0开始)
        index--;
        if(index >= 0 && index < names.length) {
            //移位的算法
            for (int i = index; i < names.length - 1; i++) {
                names[i] = names[i + 1];
            }
            //把最后一位变为null
            names[names.length - 1] = null;
            // [jack, mike, peter, jim, null]
            System.out.println("序号\t姓名");
            for(int i = 0; i < names.length; i++){
                if(names[i] == null){
                    break;
                }
                System.out.println((i+1) +"\t\t"+names[i]);
            }
        }else{
            System.out.println("输入的坐标无效");
        }
    }
}
